#include "AnaDef.h"
#include "AnaAliDef.h"
#include "IniRun.h"
#include "AliAnalysisTaskRecCosmic.h"

void run(const TString fin)
{
  TString chunkss;
  TChain *esdchain = IniRun(fin, &chunkss, kFALSE);

  const TString taskname="RecCosmic";
  
  printf("\n======> Task: %s File: %s\n", taskname.Data(), fin.Data());

  //----------------------------------------------------------
  
  AliAnalysisManager *mgr = new AliAnalysisManager();
  mgr->SetInputEventHandler(new AliESDInputHandler);

  AliAnalysisTaskRecCosmic *task = new AliAnalysisTaskRecCosmic(chunkss);
  mgr->AddTask(task);

  AliAnalysisDataContainer *cinput  = mgr->GetCommonInputContainer();
  mgr->ConnectInput(task,  0,  cinput);

  // Run the Analysis
  Int_t nentries = 10000000;
  //nentries = 1;//2000;
  if(nentries<1e6){
    printf("\n***************** MYLOG WARNING test mode!! nentries = %d *****************\n\n", nentries);
  }

  if(mgr->InitAnalysis()){  
    TStopwatch timer;
    timer.Start();
    mgr->StartAnalysis("local", esdchain, nentries);
    timer.Stop();
    timer.Print();
  }
}


int main(int argc, char *argv[])
{
  for(int ii=0; ii<argc; ii++){
    printf("%d: %s\n", ii, argv[ii]);
  }
  if(argc!=2){
    printf("argv!=2\n");exit(1);
  }

  run(argv[1]);

  return 0;
}
